home *** CD-ROM | disk | FTP | other *** search
- //like the impact shader, but makes tex coords based on direction of view for use in env map lookup
-
- //iew,projection transform
- float4x4 matViewProj;
-
- //camera position in world space
- float4 cameraPos;
-
- //size modifier of particle
- float size;
-
- //direction of up and of right
- float3 dirUp;
- float3 dirRight;
-
- //shader input
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float3 Tex : TEXCOORD0;
- };
-
- //shader output
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float2 Tex : TEXCOORD0;
- float3 Env : TEXCOORD1;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- //calc tex coords centered around 0,0 and copy normal coord though
- float2 tc=In.Tex.xy-0.5f;
- Out.Tex=In.Tex;
-
- //transform pos
- Out.Pos=mul(matViewProj,In.Pos);
-
- //rotate and expand outwards from center point, based on distance and tex coord
- float2x2 matRot={cos(In.Tex.z),sin(In.Tex.z),-sin(In.Tex.z),cos(In.Tex.z)};
- float2 posOffset=mul(matRot,tc);
-
- float dist=distance(cameraPos,In.Pos);
- Out.Pos.xy+=(1.0f/sqrt(dist))*posOffset*size;
-
- //calc env map vector that is the view direction (with corners outwards from tex coord)
- float3 dir=normalize(In.Pos.xyz-cameraPos);
- dir+=posOffset.y*dirRight;
- dir+=posOffset.x*dirUp;
- Out.Env=dir;
-
- //spit out the results
- return Out;
- }
-